#include "UDPServer.hpp"
#include <memory>
#include <stdexcept>
#include "Dictionary.hpp"

string DefaultHandler(const string &message)
{
    string result = "hahaha";
    return result + message;
}
//./udpserver port
int main(int argc, char *argv[])
{
    Enable_Console_Log_Strategy();
   

    if (argc != 2)
    {
        cerr << "Usage: " << argv[0] << " port" << endl;
        return 1;
    }
    try
    {
        Dictionary dict;
        dict.LoadDictionary();
        uint16_t port = stoi(argv[1]);
        unique_ptr<UDPServer> server = make_unique<UDPServer>(port,[&dict](const string& word, INETADDR& client) -> string {
            return dict.Translate(word,client);
        });
        server->Init();
        server->Start();
    }
    catch (const exception &e)
    {
        cerr << "Error: " << e.what() << endl;
        return 2;
    }

    return 0;
}